//
//  MainViewController.m
//  Fengshui
//
//  Created by are on 13-5-22.
//
//

#import "MainViewController.h"
#import "SGTypeViewController.h"
#import "SettingViewController.h"
#import "SoftSettingViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
     }
    return self;
} 
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad
{
    [super viewDidLoad];

    self.m_searchBar.backgroundColor=[UIColor clearColor];

    [[self.m_searchBar.subviews objectAtIndex:0]removeFromSuperview];

    for (UIView *subview in self.m_searchBar.subviews)
    {
        if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
        {  
            [subview removeFromSuperview];  
            break;  
            
        }  
        
    }
    char *lunarInfo = getLunarInfo([[NSDate date] timeIntervalSince1970]);
    NSString *lunarInfoStr = [NSString stringWithUTF8String:lunarInfo];
    NSDictionary *dic = [lunarInfoStr JSONValue];
    
    NSDate *  senddate=[NSDate date];
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY年MM月dd号"];
    NSString * locationString=[dateformatter stringFromDate:senddate];
    self.yangliLabel.text = locationString;
    [dateformatter release];

    NSString *string = [dic objectForKey:@"nongli_string"];
    string = [string stringByAppendingFormat:@"\n%@",[dic objectForKey:@"nongli_month_string"]];
    self.yinliLabel.text = string;
    // Do any additional setup after loading the view from its nib.
}



/*取消按钮*/
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
    [self doSearch:searchBar];
}

/*键盘搜索按钮*/
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    [searchBar resignFirstResponder];
    [self doSearch:searchBar];
    
    UIButton *btn =(UIButton *)[self.view viewWithTag:1];
    [self BtnAction:btn];
}

/*搜索*/
- (void)doSearch:(UISearchBar *)searchBar{
  
}

-(IBAction)BtnAction:(id)sender
{
    UIButton *button = (UIButton *)sender;
    if (button.tag == 1) {

        SGTypeViewController *viewController = [[SGTypeViewController alloc] initWithNibName:@"SGTypeViewController" bundle:nil];
        [self.navigationController pushViewController:viewController animated:YES];
        [viewController release];
        
    }
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.m_searchBar resignFirstResponder];
}
-(IBAction)setBtnAction:(id)sender
{
    SoftSettingViewController *settingViewController = [[SoftSettingViewController alloc] initWithNibName:@"SoftSettingViewController" bundle:nil];
    [self.navigationController pushViewController:settingViewController animated:YES];
    [settingViewController release];
}
 

#pragma searchbar delegate

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
